import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useState } from "react";
import classNames from "classnames";
import AntToolTip from "~/public/cpas-ui/components-ui/ant-components/AntToolTip";
import CpasIcon from "~/public/cpas-ui/components-ui/components/Icon";
import { Dropdown, Upload, Modal } from "antd";
import Tabs from "devextreme-react/tabs";
import { getCurrentSysName, SystemName, getHbTypeByZcbfid, MergeType, } from "../../../../tools/Tools";
const useImportButtonEffect = (_this) => {
    const importItems = [];
    const jsonImport = {
        key: "1",
        label: (_jsx(Upload, { name: "file", maxCount: 1, accept: ".json", beforeUpload: (info) => {
                _this.configFileUpload(info);
                return false;
            }, children: _jsx("span", { children: "\u4ECEJSON\u6587\u4EF6\u5BFC\u5165" }) })),
    };
    const excelImport = {
        key: "2",
        label: (_jsx(Upload, { name: "file", maxCount: 1, beforeUpload: (info) => {
                _this.excelImport(info);
                return false;
            }, children: _jsx("span", { children: "\u4ECEExcel\u5BFC\u5165" }) })),
    };
    if (_this.gridRef.props.ieType === "excel") {
        importItems.push(excelImport);
    }
    else if (_this.gridRef.props.ieType === "json") {
        importItems.push(jsonImport);
    }
    else {
        importItems.push(jsonImport);
    }
    return importItems;
};
const useExportButtonEffect = (_this) => {
    const exportItems = [];
    const jsonExport = {
        key: "1",
        label: (_jsx("span", { onClick: () => _this.handsonTableHeaderService.exportToJson(), children: "\u5BFC\u51FAJSON" })),
    };
    const excelExport = {
        key: "2",
        label: _jsx("span", { onClick: () => _this.exportToExcel(), children: "\u5BFC\u51FAExcel" }),
    };
    const draftExport = {
        key: "3",
        label: _jsx("span", { onClick: () => _this.exportToDraft(), children: "\u8FFD\u52A0\u5230\u5E95\u7A3F" }),
    };
    const sysName = getCurrentSysName();
    if (_this.gridRef.props.ieType === "excel") {
        exportItems.push(excelExport);
    }
    else if (_this.gridRef.props.ieType === "json") {
        exportItems.push(jsonExport);
    }
    else {
        exportItems.push(jsonExport);
    }
    if (sysName !== SystemName.MERGE && _this?.gridRef?.props?.type !== "ds") {
        exportItems.push(draftExport);
    }
    return exportItems;
};
const HandsonTabHeader = ({ _this, className }) => {
    const importItems = useImportButtonEffect(_this);
    const exportItems = useExportButtonEffect(_this);
    const [confirmDialog, setConfirmDialog] = useState(false);
    function renderMarkFormulaInfo() {
        return (_jsxs("div", { children: [_jsx("div", { children: "\u516C\u5F0F\u6807\u8BB0" }), _jsxs("ul", { style: { padding: 5 }, children: [_jsxs("li", { style: { display: "flex", alignItems: "center" }, children: [_jsx("div", { style: {
                                        width: 10,
                                        height: 10,
                                        backgroundColor: "#FFF6CC",
                                        marginRight: 10,
                                    }, className: "circle cpas-polymeric-mark" }), _jsx("span", { style: { color: "#FFF6CC" }, children: "\u805A\u5408\u6807\u6CE8" })] }), _jsxs("li", { style: { display: "flex", alignItems: "center" }, children: [_jsx("div", { style: {
                                        width: 10,
                                        height: 10,
                                        backgroundColor: "#FFDCDB",
                                        marginRight: 10,
                                    }, className: "circle cpas-polymeric-mark" }), _jsx("span", { style: { color: "#FFDCDB" }, children: "Excel\u516C\u5F0F\u6807\u6CE8" })] }), _this.props.type === "ds" && (_jsxs(_Fragment, { children: [_jsxs("li", { style: { display: "flex", alignItems: "center" }, children: [_jsx("div", { style: {
                                                width: 10,
                                                height: 10,
                                                backgroundColor: "#FFE6CF",
                                                marginRight: 10,
                                            }, className: "circle cpas-polymeric-mark" }), _jsx("span", { style: { color: "#FFE6CF" }, children: "\u5355\u5143\u683C\u53D6\u6570\u6807\u6CE8" })] }), _jsxs("li", { style: { display: "flex", alignItems: "center" }, children: [_jsx("div", { style: {
                                                width: 10,
                                                height: 10,
                                                backgroundColor: "#C8DCFE",
                                                marginRight: 10,
                                            }, className: "circle cpas-polymeric-mark" }), _jsx("span", { style: { color: "#C8DCFE" }, children: "\u52A8\u6001\u884C\u5217\u6807\u6CE8" })] }), _jsxs("li", { style: { display: "flex", alignItems: "center" }, children: [_jsx("div", { style: {
                                                width: 10,
                                                height: 10,
                                                backgroundColor: "#EADFFA",
                                                marginRight: 10,
                                            }, className: "circle cpas-polymeric-mark" }), _jsx("span", { style: { color: "#EADFFA" }, children: "\u671F\u95F4\u7C7B\u578B\u6807\u6CE8" })] }), _jsxs("li", { style: { display: "flex", alignItems: "center" }, children: [_jsx("div", { style: {
                                                width: 10,
                                                height: 10,
                                                backgroundColor: "#EADFFA",
                                                marginRight: 10,
                                            }, className: "circle cpas-main-column-mark" }), _jsx("span", { style: { color: "#EADFFA" }, children: "\u6BCD\u5217\u6807\u6CE8" })] })] }))] })] }));
    }
    const mergeType = getHbTypeByZcbfid();
    return (_jsxs("div", { className: classNames("handson-tab-header", className), children: [_jsx("div", { className: "col col1", children: _jsxs("div", { className: "row row1", children: [_this.gridRef.props.ieType !== "none" &&
                            _this.gridRef.props.type !== "zl" && (_jsxs("div", { className: "split-line", children: [_jsx("div", { className: "tools-item-inline", children: _jsx(Dropdown, { menu: { items: importItems }, trigger: ["click"], children: _jsx("span", { className: "iconfont icon-download" }) }) }), _jsx("div", { className: "tools-item-inline", children: _jsx(Dropdown, { menu: { items: exportItems }, trigger: ["click"], children: _jsx("span", { className: "iconfont icon-upload" }) }) })] })), _this.gridRef.props.type === "ds" &&
                            mergeType !== MergeType.TEMPLATE && (_jsx(AntToolTip, { placement: "bottom", title: "\u65AD\u5F00\u516C\u5F0F\u8FDE\u63A5", children: _jsx("div", { onClick: () => {
                                    _this.gridRef.triggerDisconnectFormula();
                                }, className: _this.state.formulaOff
                                    ? "tools-item cpas-menu-item-active"
                                    : "tools-item-inline", children: _jsx(CpasIcon, { fontSize: 22, type: "icon-duankaigongshilianjie", className: "cpas-icon" }) }) })), _this.gridRef.props.type !== "zl" && (_jsx(AntToolTip, { placement: "bottom", title: renderMarkFormulaInfo(), children: _jsx("div", { onClick: () => {
                                    const formulaMark = !_this.state.formulaMark;
                                    _this.gridRef.tableConfig["formulaMark"] = formulaMark;
                                    _this.setState({
                                        formulaMark,
                                    });
                                    _this.gridRef.hot.render();
                                }, className: _this.state.formulaMark
                                    ? "tools-item cpas-menu-item-active"
                                    : "tools-item-inline", children: _jsx(CpasIcon, { fontSize: 22, type: "icon-biaojigongshi1", className: "cpas-icon" }) }) })), _this.gridRef.props.type !== "zl" && (_jsx(AntToolTip, { placement: "bottom", title: "\u6E05\u7A7A\u516C\u5F0F", children: _jsx("div", { onClick: () => {
                                    setConfirmDialog(true);
                                }, className: "tools-item-inline", children: _jsx(CpasIcon, { fontSize: 22, type: "icon-clear", className: "cpas-icon" }) }) })), _this.gridRef.props.type !== "zl" && (_jsx(AntToolTip, { placement: "bottom", title: "\u884C\u6807\u7B7E\u5217\u5C55\u793A", children: _jsx("div", { className: _this.state.showRowTag
                                    ? "tools-item-inline cpas-menu-item-active"
                                    : "tools-item-inline", onClick: () => {
                                    _this.setShowRowTags();
                                }, children: _jsx(CpasIcon, { fontSize: 22, type: "icon-hangjuhefangshijihangshuxing", className: "cpas-icon" }) }) }))] }) }), _this.gridRef.props.type !== "zl" && (_jsx("div", { className: "col col2", style: { lineHeight: 34 }, children: _jsx(Tabs, { ref: _this.tabsRef, selectedIndex: _this.state.selectedIndex, onOptionChanged: _this.onTabsSelectionChanged, dataSource: _this.state.tabs, height: 35, width: 350, showNavButtons: false }) })), _jsx(Modal, { title: "\u63D0\u793A", open: confirmDialog, okText: "确认", cancelText: "取消", maskClosable: false, onOk: () => {
                    _this.gridRef.clearFormula();
                    setConfirmDialog(false);
                }, onCancel: () => {
                    setConfirmDialog(false);
                }, children: _jsx("p", { children: "\u8BE5\u64CD\u4F5C\u4F1A\u6E05\u7A7A\u5DF2\u8BBE\u7F6E\u7684\u516C\u5F0F:\u52A8\u6001\u884C\u5217\u516C\u5F0F\u3001\u671F\u95F4\u7C7B\u578B\u3001\u5355\u5143\u683C\u53D6\u6570.\u5E76\u4FDD\u7559\u5F53\u524D\u7684\u6570\u636E.\u60A8\u662F\u5426\u8981\u7EE7\u7EED" }) })] }));
};
export default HandsonTabHeader;
